/**
 * Created by John on 2016/7/7.
 */
var mongo = new Mongo("localhost");
var wordsDB = mongo.getDB("BeginningMongoDB");
var wordsColl = wordsDB.getCollection("word_stats");

var cursor = wordsColl.find({
    first: {
        $in: ['a', 'b', 'c']
    }
});
print("Words starting with a, b or c: ", cursor.count());

cursor = wordsColl.find({
    size: {
        $gt: 12
    }
});
print("Words longer than 12 characters: ", cursor.count());

cursor = wordsColl.find({
    size: {
        $mod: [2, 0]
    }
});
print("Words with even Lengths: ", cursor.count());

cursor = wordsColl.find({
    leters: {
        $size: 12
    }
});
print("Words with 12 Distinct characters: ", cursor.count());

var vowels = ['a', 'e', 'i', 'o', 'u']
cursor = wordsColl.find({
    $and: [
        {first: {$in: vowels}},
        {last: {$in: vowels}}
    ]
});
print("Words than start and end with a vowel: ", cursor.count());

cursor = wordsColl.find({
    "stats.vowels": {
        $gt: 6
    }
});
print("Words containing 7 or more vowels: ", cursor.count());

cursor = wordsColl.find({
    letters: {
        $all: vowels
    }
});
print("Words with all 5 vowels: ", cursor.count());

cursor = wordsColl.find({
    otherChars: {
        $exists: true
    }
});
print("Words with non-alphabet characters: ", cursor.count());

cursor = wordsColl.find({
    charsets: {
        $elemMatch: {
            $and: [{type: "other"}, {chars: {$size: 2}}]
        }
    }
});
print("Words with 2 non-alphabet characters: ",cursor.count());


